	
	package servlet.title;
	
	import java.io.IOException;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import service.TitleManager;
	import enitys.Title;
	
	public class AddTitle extends HttpServlet {
	
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		/**
		 * Constructor of the object.
		 */
		public AddTitle() {
			super();
		}
	
		
		public void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
				doPost(request,response);
			
		}
	
		public void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {
			//创建表单Bean 封装表单数据
			Title form = new Title();
			form.setHead(request.getParameter("head"));
			form.setText(request.getParameter("text"));
			//获取业务对象 调用业务方法 取得处理结果
			TitleManager manager = TitleManager.getInstance();
			boolean flag = manager.addTitle(form);
			//向request中设置提示信息 并进行转发
			if(flag){
				request.setAttribute("message", "添加成功！");
			}else{
				request.setAttribute("message", "添加失败！");
			}
			this.getServletConfig().getServletContext().getRequestDispatcher("/servlet/TitleInfo").forward(request, response);
			
		}
	
		/**
		 * Initialization of the servlet. <br>
		 *
		 * @throws ServletException if an error occurs
		 */
		public void init() throws ServletException {
			// Put your code here
		}
	
	}
